﻿CREATE PROCEDURE [dbo].[AddProject]
@Name NVARCHAR (50), @Description NVARCHAR (1024), @ManagerUserID INT, @EstCompletionDate DATETIME, @EstDuration INT, @ProjectTypeID INT, @StatusID INT, @Members NVARCHAR (2000), @Categories NVARCHAR (4000)
AS
DECLARE @Error int
	DECLARE @ProjectID int
	
	BEGIN TRANSACTION 

	INSERT INTO Projects
	(
		[Name],
		[Description],
		ManagerUserID,
		EstCompletionDate,
		EstDuration,
		ProjectTypeID,
		StatusID,
		CreationDate
	)
	VALUES
	(   
		@Name,
		@Description,
		@ManagerUserID,
		@EstCompletionDate,
		@EstDuration,
		@ProjectTypeID,
		@StatusID,
		getdate()
	)
	
	SET @ProjectID = @@IDENTITY

	SET @Error = @@ERROR
	IF @Error != 0 GOTO ERROR_HANDLER

	COMMIT TRANSACTION

	SELECT @ProjectID AS ProjectID  

ERROR_HANDLER:
	IF @@TRANCOUNT != 0 ROLLBACK TRANSACTION
	RETURN @Error

